from rest_framework import serializers
from personal_app.models import UserCourse,UserSection

class UserCourseSerializer(serializers.ModelSerializer):
    course_id = serializers.IntegerField(source='course.id')
    course_name = serializers.CharField(source='course.name')
    '''用户订阅课程序列化器'''
    class Meta:
        model = UserCourse
        fields = ['course_id','course_name']


class UserCourseListSerializer(serializers.ModelSerializer):
    id = serializers.IntegerField(source='course.id')
    course_name = serializers.CharField(source='course.name')
    course_icon = serializers.CharField(source='course.icon')
    '''用户订阅课程序列化器'''
    class Meta:
        model = UserCourse
        fields = ['course_id','course_name,icon']

class UserSectionSerializer(serializers.ModelSerializer):
    id = serializers.IntegerField(source='section.id')
    section_name = serializers.CharField(source='section.name')
    section_duration = serializers.CharField(source='section.duration')
    section_learn_count = serializers.CharField(source='section.learned_count')

    create_time = serializers.DateTimeField(format='%Y-%m')
    class Meta:
        model = UserSection
        fields = '__all__'

class AddSectionSerializer(serializers.ModelSerializer):
    '''增加订阅课程'''
    section = serializers.IntegerField(required=True)

    class Meta:
        model = UserSection
        fields = ('section',)